<?php
/**
 * Created by PhpStorm.
 * User: yuyj
 * Date: 16-12-16
 * Time: 下午5:04
 */

namespace mybackend\controllers;

use common\services\outstock\DeliveryOrderService;
use common\entities\myhtsq\ActionCode;
use Yii;

class DeliveryOrderController extends BaseController
{

    private $service;

    public function __construct($id, $module, DeliveryOrderService $deliveryOrderService, $config = [])
    {
        $this->service = $deliveryOrderService;
        parent::__construct($id, $module, $config);
    }
    protected function roleAuthRules()
    {
        $data = [
            'save' => ActionCode::FLOW_CENTER_OUT_STOCK,
            'sub-order-view' => ActionCode::FLOW_CENTER_QUERY,
        ];

        return [
            'actions' => array_keys($data),
            'rules'   => [
                [
                    'allow'          => true,
                    'actionCodeMaps' => $data],
            ],
        ];
    }
    public function actionSubOrderView()
    {
        $subOrderId=\Yii::$app->request->get('sub_order_id','');
        if(empty($subOrderId)){
            return $this->exportJson(false,__LINE__,'缺少sub_order_id参数！');
        }
        $data = $this->service->subOrderView($subOrderId);
        return $this->exportJson($data,$this->service->getErrCode(),$this->service->getErrMsg());
    }
    public function actionGetAllProducts(){
        $subOrderId=\Yii::$app->request->get('sub_order_id','');
        if(empty($subOrderId)){
            return $this->exportJson(false,__LINE__,'缺少sub_order_id参数！');
        }
        $res = $this->service->getAllProducts($subOrderId);
        $this->exportJson($res, $res = $this->service->getErrCode(), $res = $this->service->getErrMsg());
    }

}